package com.wwl.cms.basic;

import com.wwl.cms.basic.exception.RemoteCallFailException;

import java.io.Serializable;

/**
 * @author wwl
 * @version 1.0
 * @date 2021/2/18 14:47
 * @description:
 */
public class BaseOutput implements Serializable {

    private String message;
    /** 响应消息内容， 若响应状态返回非200，则值为失败原因 */
    private String status;

    public BaseOutput() {
        this(CommonStatus.SUCCESS);
    }

    public BaseOutput(String message) {
        this(CommonStatus.SUCCESS, message);
    }

    public BaseOutput(OutputStatus status) {
        this(status.getCode(), status.getMessage());
    }

    public BaseOutput(OutputStatus status, String message) {
        this(status.getCode(), message);
    }

    public BaseOutput(String status, String message) {
        this.status = status;
        this.message = message;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void ensureSuccess() {
        if (!CommonStatus.SUCCESS.getCode().equals(this.getStatus())) {
            throw new RemoteCallFailException(this.status, this.message);
        }
    }
}
